/*
 * @(#) $Header$
 *
 * Copyright (C) 2007  Forklabs Daniel Léonard
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

package ca.forklabs.media.jai.opimage;

import java.awt.RenderingHints;
import java.awt.image.renderable.ParameterBlock;
import javax.media.jai.CollectionImage;
import javax.media.jai.CollectionImageFactory;
import javax.media.jai.CollectionOp;
import ca.forklabs.media.jai.ImageFunction3D;
import ca.forklabs.media.jai.operator.ImageFunction3DDescriptor;

/**
 * Class {@code ImageFunction3DCIF} is a {@link CollectionImageFactory}
 * supporting the <em>imagefunction3d</em> operation.
 *
 * @author   <a href="mailto:forklabs at gmail.com?subject=ca.forklabs.media.jai.opimage.ImageFunction3DCIF">Daniel Léonard</a>
 * @version $Revision$
 */
public class ImageFunction3DCIF implements CollectionImageFactory {

//---------------------------
// Constructor
//---------------------------

   /**
    * Constructor.
    */
   public ImageFunction3DCIF() {
   // nothing
      }


//---------------------------
// Instance methods
//---------------------------

   /**
    * Gets the function parameter from the parameter block.
    * @param   pb   the parameter block.
    * @return    the function parameter.
    */
   protected ImageFunction3D getFunction(ParameterBlock pb) {
      int index = ImageFunction3DDescriptor.FUNCTION_PARAMETER_INDEX;
      ImageFunction3D function = (ImageFunction3D) pb.getObjectParameter(index);
      return function;
      }

   /**
    * Gets the width parameter from the parameter block.
    * @param   pb   the parameter block.
    * @return    the width parameter.
    */
   protected int getWidth(ParameterBlock pb) {
      int index = ImageFunction3DDescriptor.WIDTH_PARAMETER_INDEX;
      int width = pb.getIntParameter(index);
      return width;
      }

   /**
    * Gets the height parameter from the parameter block.
    * @param   pb   the parameter block.
    * @return    the height parameter.
    */
   protected int getHeight(ParameterBlock pb) {
      int index = ImageFunction3DDescriptor.HEIGHT_PARAMETER_INDEX;
      int width = pb.getIntParameter(index);
      return width;
      }

   /**
    * Gets the depth parameter from the parameter block.
    * @param   pb   the parameter block.
    * @return    the depth parameter.
    */
   protected int getDepth(ParameterBlock pb) {
      int index = ImageFunction3DDescriptor.DEPTH_PARAMETER_INDEX;
      int width = pb.getIntParameter(index);
      return width;
      }


//---------------------------
// Implemented methods from javax.media.jai.CollectionImageFactory
//---------------------------

   /**
    * Creates a {@code CollectionImage} that represents the result of applying
    * the requested operation once to each image in the collection.
    * @param   pb   the parameter block.
    * @param   hints   the rendering hints.
    * @return   the collection image containing the results.
    */
   public CollectionImage create(ParameterBlock pb, RenderingHints hints) {
      ImageFunction3D function = this.getFunction(pb);
      int width = this.getWidth(pb);
      int height = this.getHeight(pb);
      int depth = this.getDepth(pb);

      CollectionImage collection_image = new ImageFunction3DOpImage(function, width, height, depth, hints);
      return collection_image;
      }

   /**
    * It is impratical to perform the update.
    * @param old_pb   ignored
    * @param old_hints   ignored
    * @param new_pb   ignored
    * @param new_hints   ignored
    * @param old_image   ignored
    * @param op   ignored
    * @return always {@code null}.
    */
   public CollectionImage update(ParameterBlock old_pb, RenderingHints old_hints,
                                 ParameterBlock new_pb, RenderingHints new_hints,
                                 CollectionImage old_image,
                                 CollectionOp op) {
   // it is impracticable to perform the update
      CollectionImage new_image = null;
      return new_image;
      }

   }
